import { BaseSchema } from '@adonisjs/lucid/schema'

export default class extends BaseSchema {
  protected tableName = 'operation_logs'

  async up() {
    this.schema.createTable(this.tableName, (table) => {
      table.increments()
      table.integer('fk_shop_id').notNullable().unsigned().references('shops.id').comment('店铺ID')

      table.string('module', 20).comment('模块代码')
      table.string('module_name', 20).comment('模块名称')
      table.string('action', 20).comment('操作代码')
      table.string('action_name', 20).comment('操作类型')
      table.string('keywords', 200).comment('关键词')
      table.json('ip_address').nullable().comment('IP 地址')

      table.dateTime('create_time').defaultTo(this.now()).comment('创建时间')
      table.string('create_user', 20).defaultTo('admin').comment('操作人')
      table.comment('操作日志')
    })
  }

  async down() {
    this.schema.dropTable(this.tableName)
  }
}
